<?php
namespace Admin\Controller;
use Think\Controller;
class CvideoController extends Controller {
    //显示列表
    public function cvideolist(){
        $cvideomodel=M('cvideo');
        $cvideo=$cvideomodel->select();
        $this->cvideo=$cvideo;
        $this->display();
}
//添加列表
   function addcvideo(){
        $vname=$_POST['vname'];
        $people=$_POST['people'];
        $uploadtime=$_POST['uploadtime'];
        $address=$_POST['address'];
        $cvideo=D('cvideo');     
        if ($cvideo->create()) 
        {
            if (false !== $cvideo->add()) {
                //echo $user->getLastSql();
                $this->success('添加成功！', 'cvideolist');
            }
            else
            {
                $this->error('添加失败，数据错误','cvideolist');
            }
        }
            $this->display();
        }

//        function delCvideo(){
//         $jid=$_POST['jid'];
//         $Cvideo=M("Cvideo");
//         $Cvideodata=$Cvideo->where('jid='.$jid)->find();
//         unlink('./Public/upload/'.$Cvideodata['pic']);
//         if(false!=$Cvideo->where('jid='.$jid)->delete()){
//             $result['msg']=1;
//             $this->ajaxReturn($result);
//         }else{
//             $result['msg']=0;
//             $this->ajaxReturn($result);
//         }
// }

    // }
        //删除视频
        function delcvideo(){
        $vid=I('get.id');
        $data=M('cvideo')->where(array('vid'=>$vid))->find();
        if($data){
            
                $re=M('cvideo')->where(array('vid'=>$vid))->delete();
            if($re)
                $this->success('删除成功！',U('cvideolist'));
            else
                $this->error('删除失败！',U('cvideolist'));
        }else
            $this->error('视频信息意外丢失，删除失败！');
        }

      //显示修改视频
    function cvideomod(){
            $vid = $_GET['id'];
            $re = M('cvideo')->where('vid='.$vid)->find();
            $this->re = $re;
            $this->display();
        }
//修改视频
        function cvideomod1(){
            //$class = M("class");
            $vid = $_POST['vid'];
            $data['vname']=$_POST['vname'];
            $data['people'] = $_POST['people'];
            $data['uploadtime'] = $_POST['uploadtime'];
            $data['address'] = $_POST['address'];
            
            $int = M('cvideo')->where('vid='.$vid)->save($data);
            if($int){
                $this->success('修改成功！',U('cvideolist'));
            }
            else{
                echo "$data";
                $this->error('修改失败！',U('cvideolist'));
            }
    
        }
   
   //搜索课程列表
     //       public function searchCvideo(){
     //    $key = $_GET['key'];
     //    $Cvideonum = M('Cvideo')->where('kname like "%'.$key.'%"')->count();
     //    $Page = new \Think\Page($Cvideonum,2);
     //    $this->Cvideonum =$Cvideonum;
     //    $this->Cvideopage=$Page->show();
     //    if (Cvideonum) {
     //    $this->clublist=M('Cvideo')
     //        ->where('kname like "%'.$key.'%"')
     //        ->order('kid')
     //        ->limit($Page->firstRow,2)
     //        ->select();
     //    }
     // else $this->error('没有相关信息！');
     //    }  
          public function searchCvideo(){
        $key=$_POST['vname'];
        //echo "$key";
        $search=M('cvideo');
        $search=$search->where("vname like '%$key%'" )->select();
        $this->search=$search;
    
        $this->display();
   }
         
}